<div class="page-header">
    <h1><?php echo $this->titulo; ?></h1>
</div>

<form class="form-inline" role="form">
    <?php if($this->per_add){?>
    <div class="form-group">
        <a class="btn btn-success" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit', 'id' => '')); ?>"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Novo</a>
    </div>
    <?php } ?>
    <div class="form-group">
        <div class="input-group">
            <label class="sr-only" for="dtfiltro">Data</label>
            <input type="text" class="form-control" id="dtfiltro" name="dtfiltro" placeholder="Data" value="<?php echo $this->dtfiltro; ?>">
        </div>
    </div>
    <?php if($this->v_PER_ID <= 5){?>
    <div class="form-group">
        <div class="input-group">
            <label class="sr-only" for="dtfiltro">Funcionário</label>
            <select class="form-control" id="dtuser" name="dtuser">
                <option value="">Todos</option>
            <?php
                $query = 'SELECT SQL_CACHE USU_ID,USU_NOM FROM USUARIOS '
                        .' WHERE USU_STA = 1 AND PER_ID = 8'
                        .' ORDER BY USU_NOM ASC';
                $result = $this->db->fetchAll($query);
                foreach($result as $key => $row) {
                $selected = $row['USU_ID'] == $this->dtuser ? 'selected=""':'';    
            ?>
                <option <?php echo $selected; ?> value="<?php echo $row['USU_ID'];?>"><?php echo $row['USU_NOM'];?></option>
            <?php } ?>
            </select>
        </div>
    </div>
    <?php } ?>
    <div class="form-group">
        <button type="submit" class="btn btn-default">
            <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
            Pesquisar
        </button>
    </div>    
</form>

<div class="table-responsive">
    <table id="tlist" class="table table-striped table-hover">
        <thead>
            <tr>
                <th>Data</th>
                <th>Hora</th>
                <th>Serviço</th>
                <th>Cliente</th>
                <th>Telefone</th>
                <th>Mensagem</th>
                <th>Obs</th>
                <th>Funcionário</th>
                <th>Status</th>
                <th class="bc">&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($this->result as $row) { ?>
                <tr>
                    <td><?php echo Datetools::amd_dma($row['AGD_DAT']); ?></td>
                    <td><?php echo $row['AGD_HOR']; ?></td>
                    <td><?php echo $row['SER_NOM']; ?></td>
                    <td><?php echo $row['AGD_CLINOM']; ?></td>
                    <td><?php echo $row['AGD_CLITEL']; ?></td>
                    <td><?php echo $row['AGD_MSG']; ?></td>
                    <td><?php echo $row['AGD_OBS']; ?></td>
                    <td><?php echo $row['USU_NOM']; ?></td>
                    <td><?php echo tools::returnStatus($row['AGD_STA']); ?></td>
                    <td class="bc">
                        <?php if($this->per_edt){?><a class="btn btn-sm btn-primary" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit', 'id' => $row['AGD_ID'])); ?>"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Editar</a><?php }?>
                        <?php if($this->per_del && $row['AGD_STA'] == 0){?><a class="btn btn-sm btn-danger" href="javascript:void(0);" onclick="list_delete_msg('<?php echo $this->controller; ?>', <?php echo $row['AGD_ID'] ?>, $(this), '<?php echo $row['AGD_NOM'] ?>');"><span class="glyphicon glyphicon-floppy-remove" aria-hidden="true"></span> Deletar</a><?php }?>
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>
 <?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>
</div>
<script>dataPicker($('#dtfiltro'));</script>
